﻿/**************************************************************
*作者：Leon
*创建时间：2022/4/5 15:47:29
**************************************************************/
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Resources;

namespace Lad.DrawProject.Controls;

partial class BaseCanvas
{
    /// <summary>
    /// 按下鼠标中建缩放全局
    /// </summary>
    /// <param name="e"></param>
    private void Zoom(MouseButtonEventArgs e)
    {
        if (e.MiddleButton == MouseButtonState.Pressed && e.ClickCount==2 && e.Source is Canvas canvas)
        {
            var root = ScrollView;
            if (root is ScrollViewer scrollViewer)
            {

                var scaleLevel = Math.Min(scrollViewer.ViewportWidth / canvas.DesiredSize.Width, scrollViewer.ViewportHeight / canvas.DesiredSize.Height);

                ViewModel.ZoomValue= scaleLevel;
                scrollViewer.ScrollToTop();
                scrollViewer.ScrollToLeftEnd();
            }
        }
    }

    #region Format/Move
    private void EnterFormat()
    {
        StreamResourceInfo sri = Application.GetResourceStream(new Uri("pack://application:,,,/Lad.DrawProject.Controls;component/Images/FormatPainter.cur", UriKind.RelativeOrAbsolute));
        this.Cursor = new Cursor(sri.Stream);
        foreach (SelectableItemViewModelBase item in ViewModel.Items)
        {
            item.IsHitTestVisible = false;
        }
    }

    private void EnterMove()
    {
        this.Cursor = Cursors.SizeAll;
        foreach (SelectableItemViewModelBase item in ViewModel.Items)
        {
            item.IsHitTestVisible = false;
        }
    }

    private void ExitCursor()
    {
        this.Cursor = Cursors.Arrow;
        foreach (SelectableItemViewModelBase item in ViewModel.Items)
        {
            item.IsHitTestVisible = true;
        }
        Service.CursorMode = CursorMode.Normal;
    }
    #endregion

    /// <summary>
    /// 格式化颜色
    /// </summary>
    /// <param name="source"></param>
    /// <param name="target"></param>
    private void Format(SelectableItemViewModelBase source, SelectableItemViewModelBase target)
    {
        //CopyHelper.CopyPropertyValue(source.ColorViewModel, target.ColorViewModel);
        //CopyHelper.CopyPropertyValue(source.FontViewModel, target.FontViewModel);
    }
}


